package top.lingchen.spring5.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @Author 凌宸
 * @create 2021-11-30 下午 9:22
 * @Description
 * @Version 1.0
 */
@Repository
public class UserDaoImpl implements UserDao{
    // 注入 jdbcTemplate
    @Autowired
    private JdbcTemplate jdbcTemplate;
    // 多钱的方法
    // lucy 转账给 mary
    @Override
    public void addMoney() {
        String sql = "update t_account set money = money + ? where username = ?";
        jdbcTemplate.update(sql, 100, "mary");
    }
    // 少钱的方法
    @Override
    public void reduceMoney() {
        String sql = "update t_account set money = money - ? where username = ?";
        jdbcTemplate.update(sql, 100, "lucy");
    }
}
